# -*- coding: utf-8 -*-
# @File: signin.py
# @Author: Liccsu
# @Time: 12/8/2022 下午3:11
# @Project: eschool-health

import requests

try:
    from cfg import Cfg
except ModuleNotFoundError or ImportError:
    from .cfg import Cfg


class HealthSign:
    def __init__(self):
        self.user_id: str = Cfg.user_id
        # self.user_name: str = Cfg.user_name
        # self.school_code: str = Cfg.school_code
        # self.school_name: str = Cfg.school_name
        self.session_id: str = Cfg.session_id
        self.headers: dict[str, str] = {
            'User-Agent': 'Mozilla/5.0 (Linux; Android 13; PGP110 Build/TP1A.220905.001; wv) AppleWebKit/537.36 ('
                          'KHTML, like Gecko) Version/4.0 Chrome/106.0.5249.126 Mobile Safari/537.36 '
                          'ZJYXYwebviewbroswer ZJYXYAndroid tourCustomer/yunmaapp.NET/4.3.5/f399f0320a9e9e75',
            'Cookie': f'shiroJID={self.session_id}'
        }
        self.data: dict[str, str] = {'loginUserId': self.user_id, 'ymId': self.user_id, 'sessionId': self.session_id,
                                     'platform': 'YUNMA_APP'}

    def _get_user_info(self):
        requests.packages.urllib3.disable_warnings()
        response = requests.post(
            "https://h5.xiaofubao.com/marketing/login/getUserInfo",
            headers=self.headers,
            data=self.data,
            verify=False
        ).json()
        return response

    def get_detail(self):
        user_info = self._get_user_info()
        if user_info['success']:
            self.data['loginUserName'] = user_info['data']['userName']
            self.data['loginSchoolCode'] = user_info['data']['schoolCode']
            self.data['loginSchoolName'] = user_info['data']['schoolName']
            requests.packages.urllib3.disable_warnings()
            response = requests.post(
                "https://h5.xiaofubao.com/marketing/health/getDetail",
                headers=self.headers,
                data=self.data,
                verify=False
            ).json()
            return response
        else:
            return user_info if user_info else {'success': False}

    def do_detail(self, data: dict) -> dict:
        data['address'] = data['province'] + data['city'] + data['district']
        data['backWay'] = ''
        data['backWayName'] = ''
        data['backAddress'] = ''
        data['inGovQuarantine'] = ''
        data['inSchoolQuarantine'] = ''
        data['inHomeQuarantine'] = ''
        data['nucleicAcidFlag'] = ''
        data['isInCompany'] = ''
        data['backProvinceCode'] = ''
        data['backCityCode'] = ''
        data['backDistrictCode'] = ''
        data['token'] = ''
        data['loginUserId'] = data['userId']
        data['ymId'] = data['userId']
        data['sessionId'] = self.session_id
        data['loginUserName'] = data['name']
        data['loginSchoolCode'] = data['schoolCode']
        data['loginSchoolName'] = data['schoolName']
        # 体温信息
        # data['temperature'] = '36.8'
        data['platform'] = 'YUNMA_APP'
        requests.packages.urllib3.disable_warnings()
        # 请求易校园接口
        response = requests.post(
            "https://h5.xiaofubao.com/marketing/health/doDetail",
            headers=self.headers,
            data=self.data,
            verify=False
        ).json()
        return response


hs = HealthSign()

if __name__ == '__main__':
    print(hs)
